package com.wizz.trade.auth.controller;

import com.wizz.trade.auth.dto.SysRoleGroupDto;
import com.wizz.trade.auth.entity.SysRoleGroup;
import com.wizz.trade.auth.service.SysRoleGroupService;
import com.wizz.trade.common.ResponseResult;
import com.wizz.trade.common.constant.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 *
 * 权限模块/角色组
 * @author xialinrui
 * @ignore
 */
@RestController
@RequestMapping("/rolegroup")
@Slf4j
public class SysRoleGroupController {

    @Resource
    private SysRoleGroupService sysRoleGroupService;

    /**
     * 添加
     * @param sysRoleGroupDto 角色组
     * @return ResponseResult
     */
    @PostMapping
    public ResponseResult<String> addRoleGroup(@RequestBody SysRoleGroupDto sysRoleGroupDto){
        SysRoleGroup sysRoleGroup = new SysRoleGroup();
        BeanUtils.copyProperties(sysRoleGroupDto, sysRoleGroup);
        sysRoleGroupService.insert(sysRoleGroup);
        return new ResponseResult<>(StatusCode.OK, "添加成功");
    }

    /**
     * 更新
     * @param sysRoleGroupDto 角色组
     * @param id  角色组id
     * @return ResponseResult
     */
    @PutMapping("/{id}")
    public ResponseResult<String> updateRoleGroup(@RequestBody SysRoleGroupDto sysRoleGroupDto, @PathVariable("id") Long id){
        SysRoleGroup sysRoleGroup = new SysRoleGroup();
        BeanUtils.copyProperties(sysRoleGroupDto, sysRoleGroup);
        sysRoleGroup.setId(id);
        sysRoleGroupService.update(sysRoleGroup);
        return new ResponseResult<>(StatusCode.OK, "修改成功");
    }

    /**
     * 逻辑删除
     * @param id 角色组id
     * @return ResponseResult
     */
    @DeleteMapping("/{id}")
    public ResponseResult<String> deleteRoleGroup(@PathVariable("id") Long id){
        sysRoleGroupService.delete(id);
        return new ResponseResult<>(StatusCode.OK, "删除成功");
    }

    /**
     * 查询所有
     * @return ResponseResult
     */
    @GetMapping
    public ResponseResult<List<SysRoleGroup>> getAll(){
        List<SysRoleGroup> list = sysRoleGroupService.getAll();
        return new ResponseResult<>(StatusCode.OK, "查询成功", list);
    }
}
